#include "stdafx.h"
#include "ASN1PrintableString.h"

namespace AppliedCryptography
{
	ASN1PrintableString::ASN1PrintableString(ClassBits classBits, ConstructedBit constucted, TypeNumberBits number)
		: ASN1Encodable(classBits, constucted, number)
	{
	};

	ASN1PrintableString::ASN1PrintableString(ClassBits classBits, ConstructedBit constucted, TypeNumberBits number, const char* value)
		: ASN1Encodable(classBits, constucted, number),
		_value(value)
	{
	};

	ASN1PrintableString::ASN1PrintableString(ClassBits classBits, ConstructedBit constucted, TypeNumberBits number, const std::string& value)
		: ASN1Encodable(classBits, constucted, number),
		_value(value)
	{
	};

	ASN1PrintableString::ASN1PrintableString()
		: ASN1Encodable(Universal, Primitive, PrintableString)
	{
	};

	ASN1PrintableString::ASN1PrintableString(const char* value)
		: ASN1Encodable(Universal, Primitive, PrintableString),
		_value(value)
	{
	};

	ASN1PrintableString::ASN1PrintableString(const std::string& value)
		: ASN1Encodable(Universal, Primitive, PrintableString),
		_value(value)
	{
	};

	ASN1PrintableString& ASN1PrintableString::set(const std::string& value)
	{
		_value = value;
		return *this;
	};

	ASN1PrintableString& ASN1PrintableString::set(const char* value)
	{
		_value = value;
		return *this;
	};

	ASN1PrintableString& ASN1PrintableString::operator=(const char* value)
	{
		return this->set(value);
	};

	ASN1PrintableString& ASN1PrintableString::operator=(const std::string& value)
	{
		return this->set(value);
	};

	std::string ASN1PrintableString::get() const
	{
		return _value;
	};

	std::vector<byte> ASN1PrintableString::getContentBits() const
	{
		std::vector<byte> buffer;

		for(unsigned int i=0; i<_value.length(); i++)
		{
			buffer.push_back(_value.c_str()[i]);
		};

		return buffer;
	};

	ASN1PrintableString ASN1PrintableString::getInstance(ASN1Encodable& obj)
	{
		ASN1PrintableString integer;

		if(obj.getTypeBits() == integer.getTypeBits())
		{
			return *(ASN1PrintableString*)&obj;
		};

		throw std::exception("Unknow object in getInstance()!");
	};

}; // namespace AppliedCryptography
